<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
{{include file="layouts/_head"}}
</head>
<body>
<div class="main">
    <ol class="breadcrumb">
        <li><i class="icon_home iconfont"></i>首页</li>
        <li>文档管理</li>
        <li class="active">文档分类</li>
    </ol>
    <div class="bg-1 clearfix main-head-info">
        <a class="btn btn-success btn-sm" href="{{:url('/admin/article/createCategory')}}">创建分类</a>
        <span class="pull-right margin-t-5">共有 <strong>{{:count($categorys)}}</strong> 条数据</span>
    </div>
    <div class="main-con">
        {{if $categorys}}
        <table class="table table-no-border">
            <thead>
                <tr>
                    <th width="30"></th>
                    <th width="60">排序</th>
                    <th class="text-left">分类名</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {{volist name="categorys" key="key" id="vo"}}
                <tr class="group_{{$vo.parent_id}} {{if $vo.parent_id neq 0}} hide {{/if}}">
                    <td class="{{$vo.parent_id}}">{{if $vo.parent_id eq 0}}<a href="javascript:void(0);" onclick="toggle_group(this)" style="font-size: 18px;">[+]</a>{{/if}}</td>
                    <td>{{$vo.sort}}</td>
                    <td class="text-left">{{php}}for($i=1; $i<$vo['level']; $i++) {echo '|—— ';}{{/php}}{{if $vo.type == 'system'}}<i class="iconfont margin-r-3" data-toggle="tooltip" data-placement="top" data-original-title="系统使用，不允许删除">&#xe61b;</i>{{/if}}{{$vo.name}}<a class="category-addchildboard" href="/admin/article/createCategory?parent_id={{$vo.id}}">添加子分类</a></td>
                    <td>
                        {{if $vo.status == 1}}
                        <span class="label label-success">开启</span>
                        {{else}}
                        <span class="label label-danger radius">关闭</span>
                        {{/if}}
                    </td>
                    <td>{{$vo.create_time|substr=0,10}}</td>
                    <td>
                        <a class="btn btn-primary btn-xs" href="{{:url('/admin/article/editCategory')}}?id={{$vo.id}}">编辑</a>
                        <button type="button" class="btn btn-danger btn-xs" onClick="delAction({{$vo.id}})">删除</button></td>
                </tr>
                {{/volist}}
                
            </tbody>
        </table>
        {{else}}
        <p class="color-red text-center">数据为空！</p>
        {{/if}}
    </div>
</div>
{{include file="layouts/_foot"}}
<script type="text/javascript">
function toggle_group(thisNode) {
    if ($(thisNode).html() == '[-]') {
        $(thisNode).html('[+]');
    } else {
        $(thisNode).html('[-]');
    }
    $(thisNode).parents('.group_0').nextUntil('.group_0').toggleClass('hide');
}

function delAction(id){
    layer.confirm('确认删除？',function(index){
        var load = layer.load();
        $.ajax({
            type: 'GET',
            url: '{{:url("/admin/article/destoryCategory")}}?id='+id,
            dataType: 'json',
            success: function(data){
                layer.close(load);
                if (data.code == 200) {
                    layer.msg('操作成功', {time: 1500}, function() {window.location.reload();});
                } else if (data.code == 400) {
                    layer.msg(data.message);
                } else {
                    layer.msg('操作失败');
                }
            },
            error:function(data) {
                console.log(data.msg);
            },
        });     
    });
}   
</script>
</body>
</html>